<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      
        <!-- <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="职位图片">
          <a-input placeholder="请输入职位图片" v-decorator="['imgPath', {}]" />
        </a-form-item> -->
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="职位名称">
          <a-input placeholder="请输入职位名称" v-decorator="['name', {rules:[{required:true,message:'请输入'}]}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="工作地点">
          <a-input placeholder="请输入工作地点" v-decorator="['workplace', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="职位部门">
          <a-input placeholder="请输入职位部门" v-decorator="['department', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="学历要求">
          <a-input placeholder="请输入学历要求" v-decorator="['educationalRequirement', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="工作经验">
          <a-input-number placeholder="请输入工作经验" style="margin-right:5px;" :min="0" v-decorator="['workExperience', {}]" />
          年
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="语言要求">
          <a-input placeholder="请输入语言要求" v-decorator="['languageRequirement', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="HR联系人">
          <a-input placeholder="请输入联系人" v-decorator="['linkman', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="HR联系方式">
          <a-input placeholder="请输入联系方式" v-decorator="['linkPhone', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="职位描述">
          <!-- <a-input placeholder="请输入职位描述" type="textarea" v-decorator="['jobDescription', {}]" /> -->
          <j-editor v-decorator="[ 'jobDescription', {} ]" triggerChange></j-editor>
        </a-form-item>
        
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="任职要求">
          <!-- <a-input placeholder="请输入任职要求" type="textarea" v-decorator="['jobRequirements', {}]" /> -->
          <j-editor v-decorator="[ 'jobRequirements', {} ]" triggerChange></j-editor>
        </a-form-item>

		
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
  import JEditor from '@/components/jeecg/JEditor'
  export default {
    name: "CompanyPositionModal",
    components: { JEditor},
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        },
        url: {
          add: "/tc/companyPosition/add",
          edit: "/tc/companyPosition/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'companyId','imgPath','name','linkPhone','workplace','educationalRequirement','workExperience','languageRequirement','linkman','jobDescription','department','jobRequirements','status','lookCount','forwardCount','commentCount','fabulousCount','createUser','updateUser','favoriteCount'))
		  //时间格式化
          this.form.setFieldsValue({releaseTime:this.model.releaseTime?moment(this.model.releaseTime):null})
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            // formData.releaseTime = formData.releaseTime?formData.releaseTime.format('YYYY-MM-DD HH:mm:ss'):null;
            
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>